package httpServer;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created by ab on 2016/10/27.
 */
public class HttpServer {


    /***
     * start http server
     * @param port port of http server
     * @throws IOException
     */
    private ServerSocket server;
    private Main main;
    private String staticFile;

    public HttpServer(int port) throws IOException {
        server = new ServerSocket(port);
        System.out.println("   ∧＿∧\r\n" +
                "　(・∀・)／＼\r\n" +
                "　ノ つ つ ● )   The http server is run in port : " + port + "\r\n" +
                "⊂、　ノ　＼／\r\n" +
                "　 し′");
    }

    public String getStaticFile() {
        return staticFile;
    }

    public void setStaticFile(String staticFile) {
        this.staticFile = staticFile;
    }

    public Main start() {
        while (true) {
            try {
                Socket socket = server.accept();
                main=new Main(socket);
                main.setStaticFile(getStaticFile());
                Thread workThread = new Thread(main);
                workThread.start();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
